package com.x.Part2_Exception类.自定义异常;

/**
 * ClassName: ThrowTest
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.03.24 15:58
 */
public class ThrowTest {
    public static void main(String[] args) {
        Person p = new Student();
        try{
            p.setId(10);
            p.setId(-10);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println(p.id);

    }
}


class Person{
    int id;

    public void setId(int id) throws Exception{
        this.id = id;
    }
}

class Student extends Person{
    @Override
    public void setId(int id) throws BelowZeroException {
        if(id > 0)
            this.id=id;
        else{
           throw new BelowZeroException("id小于0");
        }

    }
}